package com.yonyou.iuap.controller.pc;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yonyou.iuap.pub.IDFactory;
import com.yonyou.iuap.pub.JsonUtils;
import com.yonyou.iuap.shell.entity.KmFavoriteEntity;
import com.yonyou.iuap.shell.entity.exp.FavoritePojo;
import com.yonyou.iuap.shell.pub.ResultDto;
import com.yonyou.iuap.shell.service.intf.IKmFavoriteService;

/**
 * 知识收藏表 PC  
 * 
 * autoc shiwenqiang
 * **/
@Controller
@RequestMapping("/PCfavorite")
public class PCKmfavoriteEntityController {
	private final Logger logger = (Logger) LoggerFactory.getLogger(getClass());
	private long start,end;
	@Autowired
	private IKmFavoriteService iKmFavoriteService;
	/**
	 * 知识收藏数量统计
	 * **/
	@RequestMapping(value="queryCountfavorite",method=RequestMethod.POST)
	@ResponseBody
	public String Countfavorite(@RequestBody Map map,HttpServletRequest resq,HttpServletResponse response){
		start=System.currentTimeMillis(); 
		List<FavoritePojo> pojo=iKmFavoriteService.Countfavoritepk();
		 ResultDto rsDto = new ResultDto();
		 rsDto.setStatus(0);
		 rsDto.setMessage("数据查询成功!");
		 rsDto.setData(pojo);
		 end=System.currentTimeMillis();
			logger.info("queryCountfavorite接口调用时间"+String.valueOf(end-start));
		return JsonUtils.toJsonStr(rsDto);
	}
	
	/**
	 * 新增
	 * **/
	
	@RequestMapping(value="insertfavorite",method=RequestMethod.POST)
	@ResponseBody
	public String insertfavorite(@RequestBody HashMap parMap,HttpServletRequest resq,HttpServletResponse response){
		start=System.currentTimeMillis();
		String pk_user=parMap.get("pk_user").toString();
		String pk_publish=parMap.get("pk_publish").toString();
		KmFavoriteEntity supplier=new KmFavoriteEntity();
		supplier.setPk_favorite(pk_user);
		supplier.setPk_publish(pk_publish);
		supplier.setPk_favorite(IDFactory.getInstance().getID());
		SimpleDateFormat dd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		supplier.setFavorite_time(dd.format(new Date()));
		supplier.setSealmark("N");
		supplier.setDtcreate(new Date());
		supplier.setDr(0);
		supplier.setFW_TS(new Date());
		ResultDto resultDto = iKmFavoriteService.insert(supplier);
		end=System.currentTimeMillis();
		logger.info("insertfavorite接口调用时间"+String.valueOf(end-start));
		return JsonUtils.toJsonStr(resultDto);
	}
	
	/*
	 * 取消收藏
	 * 
	 * **/
	
	@RequestMapping(value="deletefavorite",method=RequestMethod.POST)
	@ResponseBody
	public String deletefavorite(@RequestBody HashMap parMap,HttpServletRequest resq,HttpServletResponse response){
		start=System.currentTimeMillis();
		String pk_favorite=parMap.get("pk_favorite").toString();
		StringBuffer str=new StringBuffer();
		str.append("pk_favorite='"+pk_favorite+"'");
		ResultDto resultDto = iKmFavoriteService.deleteByCondition(str.toString());
		String rtn_json = JsonUtils.toJsonStr(resultDto);
		end=System.currentTimeMillis();
		logger.info("deletefavorite接口调用时间"+String.valueOf(end-start));
		return rtn_json;
	}
}
